//符合AMD规范的写在前面
define(['zepto', 'underscore', 'gmu','app/toast','app/submitData'],
    function ($, _, gmu,toast, submitData) {

        function LoginPage() {
            this.btn = $("#subBtn");
            this.phone = $('#userPhone');
            this.password = $("#userPsd");
            this.createDialog=toast.dialogBox("#dialogMsg");
            this.alertDialog=$("#dialogMsg");
        }

        LoginPage.prototype._init = function () {
            var _this = this;

            $(this.btn).on('click', function () {
                var phone = $.trim(_this.phone.val());
                var password = $.trim(_this.password.val());
                var url = ADDRESSURL + "/loginDo";

                //点击按钮验证手机号规则
                if (phone.length != 11 || phone == '') {
                    _this.alertDialog.text('手机号码不正确').dialog("open");
                    return false;
                }
                if (!(/^(13[0-9]|15[0-9]|18[0-9]|14[5|7]|18[6|8|9])\d{8}$/).test(phone)) {
                    _this.alertDialog.text('请输入正确的手机号码').dialog("open");
                    return false;
                }
                if (password == '') {
                    _this.alertDialog.text('密码不能为空').dialog("open");
                    return false;
                }
                var userData = {
                    userPhone: phone,
                    userPsd: password
                };

                submitData.send("get", url, userData, function (res) {
                    if (res.status == "1" && res.code == "000000") {
                        toast.tipsBox({message:'服务响应成功'}).auto();
                        location.href=ADDRESSURL+"/home"
                    } else if (res.status == "0" && res.code == "000222") {
                        toast.tipsBox({message:'服务响应失败'}).auto();
                    }
                });
            });
        };

        LoginPage.prototype.render = function () {
            this._init();
        };

        return LoginPage;
    });
